package com.cjh.wechat.core.service.impl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.cjh.wechat.commom.pojo.User;
import com.cjh.wechat.commom.vo.UserSearchCondition;
import com.cjh.wechat.core.dao.UserDao;
import com.cjh.wechat.core.service.UserService;

@Service
public class UserServiceImpl implements UserService
{
    @Resource
    private UserDao userDao;
    
    @Override
    public void insert(User user)
    {
        userDao.insertSelective(user);
    }
    
    @Override
    public User findById(String id)
    {
        return userDao.findById(id);
    }
    
    @Override
    public void updateByPrimaryKeySelective(User user)
    {
        userDao.updateByPrimaryKeySelective(user);
    }
    
    @Override
    public void updateStatusById(String id, String status)
    {
        User user = userDao.findById(id);
        user.setStatus(status);
        userDao.updateByPrimaryKeySelective(user);
    }
    
    // 根据条件搜索用户(分页)
    @Override
    public List<User> search(UserSearchCondition condition, int pageNum, int pageSize)
    {
        int startNum = (pageNum - 1) * pageSize;
        int endNum = (pageNum - 1) * pageSize + pageSize - 1;
        return userDao.search(condition.getCondition(), startNum, endNum);
    }
    
    // 根据条件搜索用户总条数
    @Override
    public int getSearchNum(UserSearchCondition condition)
    {
        return userDao.getSearchNum(condition.getCondition());
    }
    
}
